// pages/reviewRecord/reviewDateList/reviewDateList.js
const app = getApp();
const httpUtils = require('../../../utils/httpUtils.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
     reviewList:[], //复习记录时间列表
     pageName: '复习记录',
     imageurl: 'https://yxpmaterial.oss-cn-beijing.aliyuncs.com/',
     page: 1,
     pageSize: 20,
     hasMoreData: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that =this;
    that.getReviewRecordList();
  },

  //获取复习记录日期列表
  getReviewRecordList(){
    var that = this;
    wx.showLoading({
      title: '',
      mask: true
    })

    let bodyParam = {
      access_token: app.globalData.studentInfo.access_token ? app.globalData.studentInfo.access_token : app.globalData.access_token,
      page: that.data.page,
      size: that.data.pageSize
    }
    httpUtils.getReviewRecordList(bodyParam).then((res) => {
      var reviewList = that.data.reviewList;
      var list = res.data;
      if (that.data.page == 1) {
        reviewList = []
      }

      if (list.length < that.data.pageSize) {
        that.setData({
          reviewList: reviewList.concat(list),
          hasMoreData: false
        })
      } else {
        that.setData({
          reviewList: reviewList.concat(list),
          hasMoreData: true,
          page: that.data.page + 1
        })
      }

    });
  },

  //点击条目跳转复习任务
  toReviewTask(e){
    var that = this;
    let index = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/reviewRecord/todayreview/todayreview?date='+that.data.reviewList[index].date+"&source=1",
    })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    if (this.data.hasMoreData) {
      that.getReviewRecordList();
    } else {
      wx.showToast({
        title: '没有更多数据了',
        icon: 'none'
      })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})